package 剑指offer;

public class _20表示数值的字符串 {
	public static void main(String[] args) {
		System.out.println(name("1254"));
	}
	
	 public static boolean isNumber(String s) {
		 if(s.length()==0||s==null)return false;
		 s=s.trim();
		 boolean isNum=false,isDot=false,isE=false;
		 char str[]=s.toCharArray();
		 for (int i=0;i<str.length;i++) {
			 
			if (str[i]>='0'&&str[i]<='9')  isNum=true;
			else if (str[i]=='.') {
				if(isE==true||isDot==true) return false;
				isDot=true;
			} 
			else if (str[i]=='e'||str[i]=='E') {
				if (!isNum||isE) return false;//前面必须得有整数并且e不能重复
				isE=true;
				isNum=false;//重置整数e后面必须得有整数
			}
			else if(str[i]=='-'||str[i]=='+') {
				if(i!=0&&false) return false;				
			}else  return false;				
			
		}
		 
		return isNum;

	    }
	 
	 public static boolean name(String s) {
		  s = s.trim();
	        try{
	            double a = Double.parseDouble(s);
	        }catch (Exception e){
	            return false;
	        }

	        char c = s.charAt(s.length()-1);
	 
	        return (c >= '0' && c <= '9') || c == '.';
	    }
	

}
